package com.itheima_01.day09;

import java.util.ArrayList;

public class ArrayListTest2 {
    public static void main(String[] args) {
        ArrayList<Student> list=new ArrayList<>();
        Student stu1=new Student("张三",15);
        Student stu2=new Student("李四",17);
        Student stu3=new Student("王五",20);
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);

        ArrayList<Student> newlist = getStu(list);

        for (int i = 0; i < newlist.size(); i++) {
            Student stu=newlist.get(i);
            System.out.println(stu.getName()+"..."+stu.getAge());
        }

    }
    public static ArrayList<Student> getStu(ArrayList<Student> list){
        ArrayList<Student> newlist=new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Student stu= list.get(i);
            if (stu.getAge()<18){
                newlist.add(stu);
            }
        }
        return newlist;
    }
}
